<template>
  <div>
    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
      <div class="widget am-cf">
        <div class="widget-head am-cf">
          <div class="widget-title am-fl">跟进列表</div>
        </div>
        <div class="widget-body  am-fr">
          <customer-toolbar ref="toolbar"  class="toolbar" @search="handleFind"
                            areaTeam campusTeam studentName phoneNo alloCreateTime priority
          ></customer-toolbar>
          <div class="am-u-sm-12">
            <el-table
              :data="tableData"
              border
              maxHeight="600"
              empty-text="暂无数据"
              stripe
              style="min-width: 100%">
              <el-table-column
                min-width="100"
                prop="studentName"
                label="学生姓名">
              </el-table-column>
              <el-table-column
                min-width="130"
                prop="phoneNo"
                label="电话号码">
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="sex"
                label="性别">
                <template scope="scope">
                  <div v-if="scope.row.sex">{{scope.row.sex === '1' ? '男' : '女'}}</div>
                  <div v-else>未设置</div>
                </template>
              </el-table-column>
              <el-table-column
                min-width="150"
                prop="projectName"
                label="项目活动名称">
              </el-table-column>
              <el-table-column
                min-width="120"
                prop="projectTime"
                label="项目活动日期">
                <template scope="scope">
                  <div>{{scope.row.projectTime | formatDate}}</div>
                </template>
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="priority"
                label="紧急程度">
                <template scope="scope">
                  <div>{{{'0' : '低' ,'1': '中', '2': '高'}[scope.row.priority]}}</div>
                </template>
              </el-table-column>
              <el-table-column
                min-width="150"
                prop="campusName"
                label="意向校区">
              </el-table-column>
              <el-table-column
                min-width="165"
                prop="alloCreateTime"
                label="分配时间">
                <template scope="scope">
                  <div>{{scope.row.alloCreateTime | formatTime}}</div>
                </template>
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="gradeName"
                label="就读年级">
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="bigCategory"
                label="来源大类">
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="smallCategory"
                label="来源小类">
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="remark"
                label="备注信息">
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="followOperatorName"
                label="抢占人">
              </el-table-column>
              <el-table-column
                min-width="165"
                label="抢占时间">
                <template scope="scope">
                  <div>{{scope.row.followCreateTime | formatTime}}</div>
                </template>
              </el-table-column>
              <!-- <el-table-column
                min-width="110"
                prop="followStatus"
                label="跟进状态">
                <template scope="scope">
                  <div>{{scope.row.visitStatus === '0' ? '未跟进': '已跟进'}}</div>
                </template>
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="visitTimes"
                label="跟进次数">
                <template scope="scope">
                  <div>{{scope.row.visitTimes || 0}}</div>
                </template>
              </el-table-column> -->
              <el-table-column
                min-width="150"
                label="是否签到"
              >
                <template scope="scope">
                  <div>{{scope.row.signStatus == 1 ? '已签到': '未签到'}}</div>
                </template>
              </el-table-column>
              <el-table-column
                min-width="150"
                fixed="right"
                label="操作">
                <template scope="scope">
                  <el-button v-if="hasPermission('visit')" size="small" @click="handleRecord(scope.row)">填写回访记录</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
        <div class="am-u-lg-12 am-cf">
          <div class="am-fr">
            <pagination v-bind:total="total" v-bind:pageNo="pageNo" v-bind:pageSize="pageSize"
                        @paging="loadTableData"/>
          </div>
        </div>
        <progress-detail @completed="loadTableData" ref="progressDetail"></progress-detail>
      </div>
    </div>

  </div>
</template>
<script>
  import io from '../../lib/io'
  import CustomerToolbar from './CustomerToolbar.vue'
  import Pagination from '../base/Pagination.vue'
  import moment from 'moment'
  import ProgressDetail from './ProgressDetail.vue'

  export default{
    data:function(){
      return {
        total: 0,
        pageSize: 10,
        pageNo: 1,
        tableData: [{}],
      }
    },
    components: {
      CustomerToolbar, Pagination, ProgressDetail
    },
    watch: {

    },
    computed: {

    },
    mounted :function(){
      $(window).smoothScroll()
//      this.loadTableData()
    },
    methods:{
      handleRecord (list) {
        this.$refs.progressDetail.visitTimes = list.visitTimes || 0
        this.$refs.progressDetail.form.customerResourceId = list.customerResourceId
        this.$refs.progressDetail.show()
      },
      handleFind(formData) {
        this.formData = this.formatData(formData)
        this.loadTableData(1)
      },
      loadTableData: function (pageNo) {
        this.pageNo = pageNo || this.pageNo || 1
        this.$showLoading()
        io.post(io.myCustomerResource, Object.assign({}, this.formData, {
          pageNo: this.pageNo,
          pageSize: this.pageSize,
        }), (ret) => {
          this.$hiddenLoading()
          if (ret.success) {
            this.tableData = ret.data.list
            this.total = ret.data.total
          } else {
            this.$alert(ret.desc)
          }
        })
      },
      formatData(data) {
        return {
          areaTeamId: data.areaTeamId,
          campusId: data.campusId,
          priority: data.priority,
          visitStatus: data.visitStatus,
          studentName: data.studentName,
          phoneNo: data.phoneNo,
          followOperatorName: data.followOperatorName,
          alloCreateTimeOfStart: data.alloCreateTime[0] ? moment(data.alloCreateTime[0]).format('YYYY-MM-DD') : '',
          alloCreateTimeOfEnd: data.alloCreateTime[1] ? moment(data.alloCreateTime[1]).format('YYYY-MM-DD') : '',
        }
      }
    }
  }
</script>
<style lang="less" scoped>
</style>
